<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>LcsdAdmin</title>
    <link rel="stylesheet" href="{{URL::asset('/layui/css/layui.css')}}">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
            <!-- 列表区域 -->
                <table class="layui-table" lay-data="{height:675, url:'/admin/article/commentList', page:true, id:'idTest'}" lay-filter="demo">
                <thead>
                <tr>
                    <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
                    <th lay-data="{field:'id', width:80, sort: true, fixed: true}" class="aid">ID</th>
                    <th lay-data="{field:'aid', width:80}">文章</th>
                    <th lay-data="{field:'uid', width:80}">用户</th>
                    <th lay-data="{field:'content', width:100}">内容</th>
                    <th lay-data="{field:'addtime', width:150,templet:function(d){ return  layui.util.toDateString(d.addtime*1000,'yyyy-MM-dd')}}">添加时间</th>
                    <th lay-data="{fixed: 'right', width:280, align:'center', toolbar: '#barDemo'}">操作</th>
                </tr>
                </thead>
            </table>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
{{--                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--}}
            </script>
    </div>
    <script src="{{URL::asset('/layui/layui.js')}}"></script>
    <script>
        function child(obj) {
            var a = JSON.parse(obj);
        }

        //JavaScript代码区域
        layui.use('table', function(){
            var table = layui.table;
            //监听表格复选框选择
            table.on('checkbox(demo)', function(obj){
                console.log(obj)
            });
            //监听工具条
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.msg('你真的看不见 “ '+ data.title + ' ” 么？');
                } else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        var delUrl = "{{url('admin/article/del')}}";
                        $.ajax({
                            url:delUrl,
                            type:'post',
                            data:{
                                'data':obj,
                                '_token':'{{csrf_token()}}',
                                'type':'1',
                            },
                            success:function(data){
                                var info = JSON.parse(data);
                                if(info.code == 0){
                                    layer.confirm("状态码："+info.code+",信息："+info.msg, {
                                        btn: ['知道了'] //可以无限个按钮
                                    }, function(index, layero){
                                        parent.location.reload(); // 刷新父级页面
                                        parent.layer.close(index); //关闭当前页面
                                    });
                                    return;
                                }
                                layer.alert("状态码："+info.code+",信息："+info.msg);return;
                            },
                        })
                        layer.close(index);
                    });
                }
            });

            var $ = layui.$, active = {
                getCheckData: function(){ //获取选中数据
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;
                    layer.alert(JSON.stringify(data));

                }
                ,getCheckLength: function(){ //获取选中数目
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                }
                ,isAll: function(){ //验证是否全选
                    var checkStatus = table.checkStatus('idTest');
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                }
            };

            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</body>
</html>
